using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace StudentManagementApplication
{
    public partial class FrmInformationAboutStudent : Form
    {
        public string sPersonID;
        Business.PersonService personService = new Business.PersonService();
        Business.StudentService studentService = new Business.StudentService();
        Business.MarksService marksService = new Business.MarksService();
        Business.RollcallService rollcallService = new Business.RollcallService();
        Business.ClassService classService = new Business.ClassService();
        Business.CourseService courseService = new Business.CourseService();
        List<Entities.Rollcall> rollcallList = new List<Entities.Rollcall>();
        
        public FrmInformationAboutStudent()
        {
            InitializeComponent();
        }

        private void InitializeInformationOfStudent()
        {
            Entities.Person person= new Entities.Person();
            Entities.Marks marks = new Entities.Marks();
            Entities.Student student = new Entities.Student();
            Entities.Class _class = new Entities.Class();
            Entities.Course course = new Entities.Course();
            person = personService.GetPersonByPersonID(sPersonID);
            marks = marksService.GetMarksByStudentID(sPersonID);
            student = studentService.GetStudentByStudentID(sPersonID);
            _class = classService.GetClassByClassID(student.ClassID);
            course = courseService.GetCourseByCourseID(_class.CourseID);
            rollcallList = rollcallService.GetRollcallByStudentID1(sPersonID);
            txtStudentID.Text = person.PersonID;
            txtName.Text = person.PersonName;
            txtBirthDay.Text = person.PersonBirth.ToShortDateString();
            txtAddress.Text = person.PersonAdd;
            txtMail.Text = person.PersonMail;
            txtPhone.Text = person.PersonPhone;
            picStudent.ImageLocation = person.Picture;
            txtClass.Text = _class.ClassName;
            txtCourse.Text = course.CourseName;
            foreach (Entities.Rollcall rollcall in rollcallList)
            {
                string[] temp = { rollcall.RollcallDay.ToShortDateString(), (rollcall.Attend > 0 ? "Available" : "Absented") };
                dgvRollcall.Rows.Add(temp);
            }
        }

        private void FindRollcall()
        {
            DateTime dDay = dtpDay.Value.Date;
            Entities.Rollcall rollcall = new Entities.Rollcall();
            rollcall = rollcallService.GetRollcallByStudentIDAndRollcallDay(sPersonID, dDay);
            if (dgvRollcall.Rows.Count > 1)
            {
                int iCount = dgvRollcall.Rows.Count - 1;
                for (int i = 0; i < iCount; i++)
                {
                    dgvRollcall.Rows.RemoveAt(0);
                }
            }
            if (rollcall != null)
            {
                string[] temp = { rollcall.RollcallDay.ToShortDateString(), (rollcall.Attend > 0 ? "Available" : "Absented") };
                dgvRollcall.Rows.Add(temp);
            }
        }

        private void button4_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void FrmInformationAboutStudent_Load(object sender, EventArgs e)
        {
            InitializeInformationOfStudent();
        }

        private void dtpDay_ValueChanged(object sender, EventArgs e)
        {
            FindRollcall();
        }
    }
}